//
//  MASTableViewPriorityCell.m
//  MasonryExample
//
//  Created by 山刘 on 2020/6/11.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "MASTableViewPriorityCell.h"

@implementation MASTableViewPriorityCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.leftLabel = [LayoutUtils fixedLabelWithText:@"0万"];
        [self.contentView addSubview:self.leftLabel];
        [self.leftLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(kPadding);
        }];
        
        self.middleLabel = [LayoutUtils fixedLabelWithText:@""];
        self.middleLabel.numberOfLines = 1;
        self.middleLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.middleLabel];
        [self.middleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(kPadding);
            make.left.equalTo(self.leftLabel.mas_right).inset(kPadding.right);
        }];
        self.rightButton = [LayoutUtils createButtonWithTitle:@"置顶" target:self selector:@selector(buttonClick:)];
        [self.contentView addSubview:self.rightButton];
        [self.rightButton makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(kPadding);
            make.left.equalTo(self.middleLabel.mas_right).inset(kPadding.right);
            make.right.lessThanOrEqualTo(self.contentView).inset(kPadding.right);
        }];
        
        //宽度不够时，可以被压缩
        [self.middleLabel setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];
        // 抱紧
        [self.middleLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        //不可以被压缩，尽量显示完整
        [self.leftLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    }
    return self;
}
-(void)updateData{
    self.leftLabel.text = [NSString stringWithFormat:@"%@万",self.cellData.playCount];
    self.middleLabel.text = self.cellData.content;
    [super updateData];
}

-(void)buttonClick:(UIButton*)sender {
    
}
@end
